import java.awt.*;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2022-08-16
 * Time: 13:27
 */


public class Solution {

    public ListNode EntryNodeOfLoop(ListNode pHead){
        HashSet<ListNode> set=new HashSet<>();//利用哈希，记录结点，当重复有节点出现，说明有循环结点
        while(pHead!=null){
            if(set.contains(pHead)){
                return pHead;
            }
            set.add(pHead);//加入没有重复的节点
            pHead=pHead.next;
        }

        return null;

    }
}

/*
public class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }

    public class Solution {
        public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {
            ListNode l1 = pHead1;
            ListNode l2 = pHead2;
            while (l1 != l2) {
                if (l1 == null) {
                    return pHead2;
                } else {
                    return l1.next;
                }
                if(l2 == null) {
                    return pHead1;
                } else {
                    return l2.next;
                }
            }
            return l1;

        }


    }

    public static void main(String[] args) {

    }

}

*/
